<?php

use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;

return new class extends Migration
{
    /**
     * Run the migrations.
     */
    public function up(): void
    {
        Schema::create('dawn_osses', function (Blueprint $table) {
            $table->bigIncrements('id')->comment('文件ID');
            $table->unsignedBigInteger('user_id')->comment('所属用户ID');
            $table->string('file_name', 255)->comment('原始文件名');
            $table->string('file_path', 255)->comment('文件存储路径');
            $table->string('file_type', 50)->comment('文件类型(后缀名)');
            $table->unsignedBigInteger('file_size')->comment('文件大小(字节)');
            $table->string('storage_type', 20)->default('local')->comment('存储类型：local-本地存储');
            $table->string('mime_type', 100)->nullable()->comment('文件MIME类型');
            $table->string('file_hash', 32)->nullable()->comment('文件MD5哈希值，用于去重');
            $table->tinyInteger('status')->default(1)->comment('文件状态：1-正常 0-已删除');
            $table->timestamps();

            // 添加索引
            $table->index('user_id');
            $table->index('status');
            $table->index('created_at');
            $table->index('file_hash'); // 添加文件哈希索引，用于去重查询
        });
    }

    /**
     * Reverse the migrations.
     */
    public function down(): void
    {
        Schema::dropIfExists('dawn_osses');
    }
};
